import Vue from 'vue'
import Router from 'vue-router'

const VueRouterPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return VueRouterPush.call(this, location)
}

Vue.use(Router)

/* Layout */
import Layout from '../layout'

/* Router Modules */
/* import systemRouter from './modules/systemManage'*/
import userRouter from './modules/userManage'
import personnelManageRouter from './modules/personnelManage'
import systemRouter from './modules/systemManage'
import approvalsRouter from './modules/approvalsManage'
import appprovalProManageRouter from './modules/appprovalProManage'
import projectClarificaitonRouter from './modules/projectClarificaiton'
import projectProgressRouter from './modules/projectProgressManage'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/pages/index/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/pages/index/views/error-page/404'),
    hidden: true
  },
  /*  {
    path: '/project-screen',
    component: () => import('@/pages/index/views/screen/ProjectScreen.vue'),
    name: 'ProjectScreen',
    hidden: true
  },*/
  // {
  //   path: '/project-screen',
  //   component: () => import('@/pages/index/views/screen2/ProjectScreen.vue'),
  //   name: 'ProjectScreen',
  //   hidden: true
  // },
  {
    path: '/401',
    component: () => import('@/pages/index/views/error-page/401'),
    hidden: true
  },
  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/dashboard',
  //   meta: {
  //     icon: 'dashboard'
  //   },
  //   children: [
  //     {
  //       path: 'dashboard',
  //       component: () => import('@/pages/index/views/home/home.vue'),
  //       name: 'Dashboard',
  //       meta: { title: '首页' }
  //     }
  //   ]
  // },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    meta: {
      icon: 'dashboard'
    },
    children: [
      {
        path: 'dashboard',
        component: () => import('@/pages/index/views/Enterprise/enterprise-manage.vue'),
        name: 'Dashboard',
        meta: { title: '动火信息汇总', noCache: true, affix: true }
      }
    ]
  },
  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/pages/index/views/profile/index'),
        name: 'Profile',
        meta: { title: 'profile', icon: 'user', noCache: true }
      }
    ]
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  // {
  //   path: '/permission',
  //   component: Layout,
  //   redirect: '/permission/page',
  //   alwaysShow: true, // will always show the root menu
  //   name: 'Permission',
  //   meta: {
  //     title: 'permission',
  //     icon: 'lock',
  //     roles: ['admin', 'editor'] // you can set roles in root nav
  //   },
  //   children: [
  //     {
  //       path: 'page',
  //       component: () => import('@/pages/index/views/permission/page'),
  //       name: 'PagePermission',
  //       meta: {
  //         title: 'pagePermission',
  //         roles: ['admin'] // or you can only set roles in sub nav
  //       }
  //     },
  //     {
  //       path: 'directive',
  //       component: () => import('@/pages/index/views/permission/directive'),
  //       name: 'DirectivePermission',
  //       meta: {
  //         title: 'directivePermission'
  //         // if do not set roles, means: this page does not require permission
  //       }
  //     },
  //     {
  //       path: 'role',
  //       component: () => import('@/pages/index/views/permission/role'),
  //       name: 'RolePermission',
  //       meta: {
  //         title: 'rolePermission',
  //         roles: ['admin']
  //       }
  //     }
  //   ]
  // },
  //
  // {
  //   path: '/icon',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/pages/index/views/icons/index'),
  //       name: 'Icons',
  //       meta: { title: 'icons', icon: 'icon', noCache: true }
  //     }
  //   ]
  // },

  /** when your routing map is too long, you can split it into small modules **/
  /*  systemRouter,*/

  // personnelManageRouter,
  projectProgressRouter,
  approvalsRouter,
  projectClarificaitonRouter,
  appprovalProManageRouter,
  // userRouter,
  systemRouter,
  // {
  //   path: '/enterprise',
  //   component: Layout,
  //   redirect: '/enterprise/manage',
  //   name: 'ENTERPRISE',
  //   alwaysShow: true,
  //   meta: {
  //     title: '企业管理',
  //     icon: 'user'
  //   },
  //   children: [
  //     {
  //       path: 'manage',
  //       component: () => import('@/pages/index/views/Enterprise/enterprise-manage.vue'),
  //       name: 'ENTERPRISE-MANAGE',
  //       meta: { title: '企业信息管理' }
  //     }
  //   ]
  // },
  // {
  //   path: '/crafts',
  //   component: Layout,
  //   redirect: '/crafts/manage',
  //   name: 'crafts',
  //   meta: {
  //     title: '工艺管理',
  //     icon: 'icon-gongymanage'
  //   },
  //   children: [
  //     {
  //       path: 'contract',
  //       component: () => import('@/pages/index/views/crafts/crafts-info-manage.vue'),
  //       name: 'ContractManage',
  //       meta: { title: '工艺管理' }
  //     }
  //   ]
  // },
  // {
  //   path: '/plan',
  //   component: Layout,
  //   redirect: '/plan/manage',
  //   name: 'plan',
  //   meta: {
  //     title: '计划管理',
  //     icon: 'icon-plabgl'
  //   },
  //   children: [
  //     {
  //       path: 'plan',
  //       component: () => import('@/pages/index/views/plan/plan-info-manage.vue'),
  //       name: 'PlanInfoManage',
  //       meta: { title: '计划管理' }
  //     }
  //   ]
  // },
  // {
  //   path: '/count',
  //   component: Layout,
  //   redirect: '/count/manage',
  //   name: 'count',
  //   meta: {
  //     title: '人员信息统计',
  //     icon: 'ico-personalstat'
  //   },
  //   children: [
  //     {
  //       path: 'dataType',
  //       component: () => import('@/pages/index/views/count/user-count-manage.vue'),
  //       name: 'UserCountInfo',
  //       meta: { title: '人员信息统计' }
  //     }
  //   ]
  // },
  // {
  //   path: '/project',
  //   component: Layout,
  //   redirect: '/project/manage',
  //   name: 'project',
  //   meta: {
  //     title: '项目管理',
  //     icon: 'icon-xmxi'
  //   },
  //   children: [
  //     {
  //       path: 'manage',
  //       component: () => import('@/pages/index/views/project/project-manage.vue'),
  //       name: 'ProjectManage',
  //       meta: { title: '项目信息管理' }
  //     },
  //     {
  //       path: 'position',
  //       component: () => import('@/pages/index/views/project/PositionManage.vue'),
  //       name: 'PositionManage',
  //       meta: { title: '项目岗位管理' }
  //     },
  //     {
  //       path: 'member',
  //       component: () => import('@/pages/index/views/project/MemberManage.vue'),
  //       name: 'MemberManage',
  //       meta: { title: '项目成员管理' }
  //     }
  //   ]
  // },
  {
    path: '/video',
    component: Layout,
    redirect: '/video/manage',
    name: 'project',
    meta: {
      title: '项目计划管理',
      icon: 'icon-xmxi'
    },
    children: [
      {
        path: 'manage',
        component: () => import('@/pages/index/views/system-manage/project_plan.vue'),
        name: 'projectPlan',
        meta: { title: '项目计划管理' }
      }
    ]
  },
  // {
  //   path: '/patrol',
  //   component: Layout,
  //   redirect: '/patrol/manage',
  //   name: 'project',
  //   meta: {
  //     title: '巡检管理',
  //     icon: 'icon-xmxi'
  //   },
  //   children: [
  //     {
  //       path: 'manage',
  //       component: () => import('@/pages/index/views/patrol/patrol-manage.vue'),
  //       name: 'PatrolManage',
  //       meta: { title: '巡检管理' }
  //     }
  //   ]
  // },
  // {
  //   path: '/equipment',
  //   component: Layout,
  //   redirect: '/equipment/manage',
  //   name: 'project',
  //   meta: {
  //     title: '设备报警',
  //     icon: 'icon-xmxi'
  //   },
  //   children: [
  //     {
  //       path: 'manage',
  //       component: () => import('@/pages/index/views/equipment/equipment-manage.vue'),
  //       name: 'EquipmentManage',
  //       meta: { title: '设备报警管理' }
  //     }
  //   ]
  // },
  // {
  //   path: '/gateway',
  //   component: Layout,
  //   redirect: '/gateway/manage',
  //   name: 'gateway',
  //   meta: {
  //     title: '网关管理',
  //     icon: 'icon-xmxi'
  //   },
  //   children: [
  //     {
  //       path: 'manage',
  //       component: () => import('@/pages/index/views/gateway/gateway-manage.vue'),
  //       name: 'GatewayManage',
  //       meta: { title: '网关信息管理' }
  //     },
  //     {
  //       path: 'equipment',
  //       component: () => import('@/pages/index/views/gateway/gateway-equipment-manage.vue'),
  //       name: 'GatewayEquipmentManage',
  //       meta: { title: '网关关联设备管理' }
  //     }
  //   ]
  // },
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  base: 'admin',
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
